package com.example.ali.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;

import com.allure.lbanners.LMBanners;
import com.example.ali.R;
import com.example.ali.adapter.IndexBannerImgAdapter;
import com.example.ali.adapter.IndexListViewAdpter;
import com.example.ali.entiy.News;
import com.example.ali.util.Spllite;
import com.example.ali.view.ListViewForScrollView;
import com.example.ali.view.RoundImageView;
import com.githang.statusbar.StatusBarCompat;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends AppCompatActivity {
    public Spllite spllite;

    ArrayList<Integer> Imagesurl = new ArrayList<Integer>();

    @BindView(R.id.imgplus)
    RoundImageView imgplus;
    @BindView(R.id.imageView3)
    ImageView imageView3;
    @BindView(R.id.textView2)
    TextView textView2;
    @BindView(R.id.textView3)
    TextView textView3;
    @BindView(R.id.go_studentlist)
    LinearLayout goStudentlist;
    @BindView(R.id.banners)
    LMBanners banners;
    @BindView(R.id.selectcity)
    Spinner selectcity;
    @BindView(R.id.searchView)
    EditText searchView;
    @BindView(R.id.imageView4)
    ImageView imageView4;
    @BindView(R.id.textView5)
    TextView textView5;
    @BindView(R.id.imageView6)
    ImageView imageView6;
    @BindView(R.id.indexlistview)
    ListViewForScrollView indexlistview;
    public ArrayList<News> listnews;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        StatusBarCompat.setStatusBarColor(this, ContextCompat.getColor(this, R.color.colorstatus));
        ButterKnife.bind(this);
        //StatusBarCompat.setStatusBarColor(this, 0);
        indexlistview.setAdapter(new IndexListViewAdpter(this, getdata()));
        banners = (LMBanners) findViewById(R.id.banners);
        initBanners();
        List<String> list = new ArrayList<String>();
        list.add("上海");
        list.add("北京");
        list.add("深圳");
        list.add("香港");
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.index_spinner_item, list);
        adapter.setDropDownViewResource(R.layout.index_dropdown_stytle);
        Spinner sp = (Spinner) findViewById(R.id.selectcity);
        sp.setAdapter(adapter);

    }

    private void initBanners() {
        Imagesurl.add(R.mipmap.banner1);
        Imagesurl.add(R.mipmap.banner1);
        Imagesurl.add(R.mipmap.banner1);
        banners.setAutoPlay(true);//自动播放
        banners.setVertical(false);//是否可以垂直
        banners.setScrollDurtion(222);//两页切换时间
        banners.setCanLoop(true);//循环播放
        banners.setAdapter(new IndexBannerImgAdapter(this), Imagesurl);
    }

    //停止事件,节省资源
    @Override
    protected void onPause() {
        super.onPause();
        banners.stopImageTimerTask();
    }

    ArrayList<News> getdata() {
        listnews = new ArrayList<News>();
        News news = new News();
        news.setTitle("我是标题");
        news.setData("2017年10月5日");
        news.setContent("我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容");
        Integer img = R.mipmap.activity01;
        news.setImg(img);
        listnews.add(news);
        News newss = new News();
        newss.setTitle("我是标题");
        newss.setData("2017年10月5日");
        newss.setContent("我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容");


        Integer imgs = R.mipmap.activity01;
        newss.setImg(imgs);
        listnews.add(newss);
        return listnews;

    }

    @Override
    protected void onResume() {
        super.onResume();
        banners.startImageTimerTask();
    }

    @OnClick(R.id.go_studentlist)
    public void onViewClicked() {
        Intent intent = new Intent(this, Schoolactivity.class);
        startActivity(intent);
    }


}
